package com.people.netmon.reddit.monitor.controller;

import ai.people.netmon.framework.domain.reddit.request.RedditRequestParameter;
import ai.people.netmon.framework.domain.reddit.vo.RedditAccountVO;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.framework.model.response.Result;
import ai.people.netmon.framework.utils.ResultUtil;
import com.people.netmon.reddit.probe.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * reddit账号控制器
 *
 * @author yuanqinglong
 * @date 2022/3/8 13:31
 */
@Validated
@RestController
@RequestMapping("/user")
public class AccountController {


    @Autowired
    private AccountService accountService;


    /**
     * 通过用户名获取用户
     *
     * @param userName 用户名
     * @return {@link Result}<{@link RedditAccountVO}>
     */
    @GetMapping("/{userName}")
    public Result<RedditAccountVO> getUserByUserName(@PathVariable("userName") String userName){
        RedditAccountVO redditUser = accountService.getUserByUsername(userName);
        return ResultUtil.success(redditUser);
    }


    /**
     * 用户列表
     *
     * @param requestParameter 请求参数
     * @return {@link Result}<{@link RedditAccountVO}>
     */
    @PostMapping("/listUsers")
    public Result<RedditAccountVO> listUsers(@RequestBody RedditRequestParameter requestParameter){
        PageResponse<RedditAccountVO> userPageResponse = accountService.listUsers(requestParameter);
        return ResultUtil.success(userPageResponse);
    }

}
